<script>
	import {
		i18n,
		t
	} from '@/locale/index'

	export default {
		onLaunch: function() {
			const self = this
			// uni.hideTabBar();
			// 先本地生成一个随机 access-token
			if (!uni.getStorageSync('access-token')) {
				uni.setStorageSync('access-token', this.$util.randomString(64))
				// uni.setStorageSync('access-token', 'oq1zp19baxln9vt29bp3qfs0lzcuayfsjldhjnv1rfbj374pn4qbghfzgiv2s590')
			}

			// #ifdef APP
			if (uni.getSystemInfoSync().platform == 'ios') {
				var CALLBACK = function(res) {
					if (res.isConnected) {
						self.getSettingsBase(true)
					}
				}
				uni.offNetworkStatusChange(CALLBACK)
				uni.onNetworkStatusChange(CALLBACK)
			}
			// #endif

			this.getSettingsBase()
		},
		methods: {
			getSettingsBase(isConnected = false) {
				this.$http.get('settings').then(res => {
					uni.setStorageSync('settings', res)
					// console.log(uni.getLocale(), "手机语言");
					if (!uni.getStorageSync('user_language')) {
						const locale = res.system.locale
						if (locale == 'zh_cn') {
							uni.setLocale('zh-Hans')
						} else if (locale == 'zh_hk') {
							uni.setLocale('zh-Hant')
						} else {
							uni.setLocale('en')
						}

						i18n.global.locale = locale
						uni.setStorageSync('user_language', locale)
						this.$util.setTabBarLanguage()
					}

					uni.$emit('loadSettings', true)
				})
			}
		}
	};
</script>

<style lang="scss">
	@import '@/uni_modules/uni-scss/index.scss';
	@import '@/common/styles/common.scss';

	// #ifndef APP-PLUS-NVUE
	@import '@/static/iconfont/iconfont.scss';
	@import '@/static/iconfont/iconfont.css';

	page {
		background-color: #f6f6f6;
		min-height: 100vh;
		// padding-bottom: calc(env(safe-area-inset-bottom) + 20px);
	}

	// #endif
</style>